﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace EbookCopier
{
    /// <summary>
    /// Cmder 自定义属性。
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class CmderAttribute : Attribute
    {
        private string _description;
        private bool _hasEditableOptions = false;
        private string _id;
        private string _name;


        /// <summary>
        /// 初始化类 <see cref="CmderAttribute"/> 的新实例。
        /// </summary>
        /// <param name="id">Cmder 的 GUID</param>
        /// <param name="name">Cmder 的 名称</param>
        public CmderAttribute(string id, string name)
        {
            this._description = string.Empty;
            this.Id = id;
            this.Name = name;
        }
        /// <summary>
        /// 获取或设置 Cmder 的描述文本。
        /// </summary>
        /// <value>The description.</value>
        public string Description
        {
            get
            {
                return this._description;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Cmder.Description");
                }
                this._description = value;
            }
        }

        /// <summary>
        /// 获取或设置 Cmder 是否支持选项编辑。
        /// </summary>
        /// <value>True=支持; False=不支持。</value>
        public bool HasEditableOptions
        {
            get
            {
                return this._hasEditableOptions;
            }
            set
            {
                this._hasEditableOptions = value;
            }
        }

        /// <summary>
        /// 获取或设置 GUID 字符串。
        /// </summary>
        /// <value>GUID 字符串</value>
        public string Id
        {
            get
            {
                return this._id;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Cmder.Id");
                }

                try
                {
                    new Guid(value);
                }
                catch
                {//不是有效的 GUID 字符串
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The value specifed ({0}) was not a GUID", new object[] { value }), "Cmder.Id");
                }

                this._id = value;
            }
        }
        /// <summary>
        /// 获取或设置 Cmder 的名称。
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Cmder.Name");
                }
                this._name = value;
            }
        }
    }
}
